<?php
/*******************************************************************************
 * $Date:: 29 May 2010 00:14:33												   $
 * $Revision::																   $
 * $Author:: Tuan Duong													   	   $
 * $Comment::															   	   $
 ******************************************************************************/

class Bet_ApplicationController extends Zend_Controller_Action
{
	const ERROR_PAMAMETERNOTFOUND_ACTION = "parameternotfound";
	const ERROR_NOAUTHORIZED_ACTION = "noauthorized";
	const ERROR_DATANOTFOUND_ACTION = "datanotfound";
	const ERROR_REQUIREDLOGIN_ACTION    = "requiredlogin";

	public function postDispatch()
	{
	}

	protected function _getIntParam($paramName, $default = null)
	{
		if ($this->_hasParam($paramName)) {
			$value = $this->_getParam($paramName);
			if (is_numeric($value))
			return (int)$value;
		}

		return $default;
	}

	protected function requirePostMethod()
	{
		if (!$this->getRequest()->isPost()) {
		}
		throw new Bet_Exceptions_PostRequiredException();
	}

	/**
	 * @param string|null $back if back is null, use the current url
	 */
	protected function requireLoggedIn($back = null)
	{
	}

	/**
	 * Show error message
	 * @param string|array $errorMessage
	 * @todo: apply zend translation here
	 * @todo: raise CustomError here, leave the error handling for ErrorController
	 */
	protected function showError($errorMessage) {
		if (!is_array($errorMessage)) {
			$this->view->message = $errorMessage;
		} else {
			$this->view->message = implode("<br />", $errorMessage);
		}
		//      $this->_forward("custom-error", "error");
		throw new Bet_Exceptions_CustomErrorException();
	}

	/**
	 * Use ErrorController to handle error
	 * @param string $errorAction
	 */
	protected function error($errorAction) {
		$this->_forward($errorAction, "error");
	}

	protected function getResource($resourceName) {
		$bootstrap = $this->getInvokeArg('bootstrap');
		if (!$bootstrap->hasPluginResource($resourceName)) {
			return false;
		}
		$resource = $bootstrap->getResource($resourceName);
		return $resource;
	}

}


